package org.example.method;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;

public class Test01 {

    public static class Person {

        private String name;
        private Double salary;


        public Person(String name, Double salary) {
            this.name = name;
            this.salary = salary;
        }

        public Double getSalary2(Long seed) {
            return new Random(seed).nextDouble();
        }

        public Double getSalary() {
            return salary;
        }


        public String getName2() {

            return "x" + this.name;
        }
    }


    //对象::实例方法
    public static void main(String[] args) {


        PrintStream ps = System.out;
        Consumer<String> con1 = ps::println;
        con1.accept("aaa");


        Person person = new Person("zhangsan", 4000.0);

        Function<Long, Double> salary = person::getSalary2;


        Double d = salary.apply(1000L);

        System.out.println(d);


        //实例::实例方法
        Supplier<String> name2 = person::getName2;
        String name2res = name2.get();
        System.out.println(name2res);


        List<Person> personList = new ArrayList<>();

        personList.add(person);

        //类::实例方法
        List<Double> doubles = personList.stream().map(Person::getSalary).collect(Collectors.toList());

        System.out.println(doubles);


        List<String> list = new ArrayList<>();

        //构造器的引用
        Supplier<ArrayList> strings = ArrayList::new;

        strings.get();





    }
}
